﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Chapter24.Examples
{
    using System.Xml.Linq;

    public class Code07
    {
        public static void BeginEx03()
        {
            var doc = new XDocument();
            var customers = new XElement("customers");

            var id = new XAttribute("ID", "A");
            var city = new XAttribute("City", "New York");
            var region = new XAttribute("Region", "North America");

            var item = new XAttribute("Item", "Widget");
            var price = new XAttribute("Price", 100);
            var order = new XElement("order", item, price);
            var customer = new XElement("customer", id, city, region);
            customer.Add(order);

            item = new XAttribute("Item", "Tire");
            price = new XAttribute("Price", 200);
            order = new XElement("order", item, price);
            customer.Add(order);
            customers.Add(customer);

            id = new XAttribute("ID", "B");
            city = new XAttribute("City", "Mumbai");
            region = new XAttribute("Region", "Asia");

            item = new XAttribute("Item", "Oven");
            price = new XAttribute("Price", 501);
            order = new XElement("order", item, price);
            customer = new XElement("customer", id, city, region);
            customer.Add(order);
            customers.Add(customer);
            doc.Add(customers);

            Console.WriteLine(doc);
            Console.WriteLine("Press Enter/Return to continue...");
            Console.ReadLine();
        }
    }
}
